/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Model;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 *
 * @author agung
 */
public class User {

    private String username;
    private String password;

    public User(String username, String password) {
        this.username = username;
        this.password = password;
    }

    public boolean isLogin(User user) throws SQLException {
        Connection con = KoneksiDB.Koneksi.open();
        Statement stat = con.createStatement();
        String cek = "select * from TABEL_USER where USERNAME='" + username + "'";
        ResultSet res = stat.executeQuery(cek);
        String cekUser = null;
        String cekPass = null;
        while (res.next()) {
            cekUser = res.getString("USERNAME");
            cekPass = res.getString("PASSWORD");
        }
        if (username.equalsIgnoreCase(cekUser) && password.equals(cekPass)) {
            return true;
        } else {
            return false;
        }
    }
    
    public boolean isAdmin(User user) throws SQLException {
        Connection con = KoneksiDB.Koneksi.open();
        Statement stat = con.createStatement();
        String cek = "select * from TABEL_USER where USERNAME='" + username + "'";
        ResultSet res = stat.executeQuery(cek);
        String cekUser = null;
        String cekPass = null;
        while (res.next()) {
            cekUser = res.getString("USERNAME");
            cekPass = res.getString("PASSWORD");
        }
        if (username.equalsIgnoreCase(cekUser) && password.equals(cekPass) && cekUser.contains("admin")) {
            return true;
        } else {
            return false;
        }
    }
    
}
